home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / basic / pbasmlib.zip / DOS.DOC < prev    next >
Text File  |  1994-02-12  |  43KB  |  1,191 lines

  1. PBASMLIB Assembly Language Routines for PB3C
  2. Version 1.0
  3. MS-DOS Function Interface (DOS.ASM)
  4. (C) Copyright 1994 by Tim Gerchmez
  5. All Rights Reserved.
  6.  
  7. This module contains many routines that provide a low-level interface
  8. to MS-DOS functions.  It is contained in the PBASMLIB.PBL library, and
  9. the routines will be immediately accessible to your programs by including
  10. the statements $INCLUDE "PBASMLIB.INC" and $LINK "PBASMLIB.PBL" at the top
  11. of your programs.
  12.  
  13. ================================================================================
  14. function bootdrive
  15.  
  16. DOS 4+ only - Returns drive system was booted from.
  17.  
  18. bootdrive: Returns boot drive number (1=A, 2=B...)
  19.  
  20. Example: print bootdrive
  21.  
  22. ================================================================================
  23. function breakflag
  24.  
  25. Returns the status of the DOS BREAK flag, which affects
  26. CTRL-C checking during DOS function calls. See SETBREAK.
  27.  
  28. breakflag: Returns 0 if BREAK=OFF, or 1 if BREAK=ON.
  29.  
  30. Example: b%=breakflag
  31.  
  32. ================================================================================
  33. function bytesfree(d%)
  34.  
  35. Same as DRIVESPACE - used as a synonym in case you find
  36. the command BYTESFREE easier to remember.  See DRIVESPACE
  37. for details.
  38.  
  39. d%: Set to disk to check (0=current, 1=A, 2=B...)
  40. bytesfree: Returns bytes free on specified drive
  41.  
  42. Example: print bytesfree(1)
  43.  
  44. ================================================================================
  45. sub changedir(p$,er%)
  46.  
  47. Sets the specified directory to be the current directory.
  48. Same as PB's CHDIR command, but returns an error code instead
  49. of forcing you to trap errors with ON ERROR.
  50.  
  51. p$: Set to path of directory to change to
  52. er%: Returns error code, or 0 if OK.
  53.  
  54. Example: changedir p$,er% 'er% = 0 if ok or error code.
  55.  
  56. ================================================================================
  57. function charin$
  58.  
  59. Reads a character from the keyboard without echoing it
  60. to the display.  If no character ready, waits for one.
  61. No CTRL-C checking, and may be redirected.  Call twice
  62. to read extended ASCII codes (first call will return 0).
  63.  
  64. charin$: Returns character user typed
  65.  
  66. Example: print charin$
  67.  
  68. ================================================================================
  69. function charinecho$
  70.  
  71. Inputs a character from the keyboard and echos it
  72. to the display.  If no character is available, waits
  73. until one is.  Input can be redirected.  Call twice
  74. to read extended ASCII codes (first call will return
  75. a zero).  Note: PowerBASIC's cursor position is NOT
  76. updated by this routine (just the DOS/BIOS cursor).
  77.  
  78. charinecho$: Returns with character entered.
  79.  
  80. Example: a$ = charinecho$
  81.  
  82. ================================================================================
  83. sub charout(a$)
  84.  
  85. Outputs a character to the currently active video
  86. display, or standard output device if redirected.
  87.  
  88. a$: Set to single character to display.  If string is
  89.     longer than one character, only the first character
  90.     will be displayed.
  91.  
  92. Example: charout "A"
  93.  
  94. ================================================================================
  95. sub closefile(h%)
  96.  
  97. Closes a file previously opened with OPENFILE or MAKEFILE.
  98. Use the handle returned by these routines.
  99.  
  100. h%: Set to handle returned by OPENFILE or MAKEFILE
  101.  
  102. Example: closefile h1%
  103.  
  104. ================================================================================
  105. sub commitfile(h%)
  106.  
  107. Forces all data in MS-DOS buffers to be written to a device,
  108. and updates the directory entry if a file.  This has the
  109. same effect as flushing, closing and reopening a file again.
  110.  
  111. h%: Set to handle of file to commit
  112.  
  113. Example: commitfile h%
  114.  
  115. ================================================================================
  116. function countryinfo$
  117.  
  118. Returns a string containing information regarding the current
  119. MS-DOS country-dependent information (MS-DOS 2+, PC-DOS 3+ only).
  120.  
  121. countryinfo$: Returns a string containing the following info
  122.               (use MID$ to separate out information):
  123. Bytes 1-2: date format (0=USA MDY, 1=Europe DMY, 2=Japan YMD)
  124. Bytes 3-7: ASCIIZ currency symbol string
  125. Byte 8 :   Thousands separator character
  126. Byte 10:   Decimal separator character
  127. Byte 12:   Data separator character
  128. Byte 14:   Time separator character
  129. Byte 16:   Currency format
  130. Byte 17:   Number of digits after decimal in currency
  131. Byte 18:   Time format (0=12-hour, 1=24-hour clock)
  132. Bytes 19-22: Case-map call address
  133. Byte 23:   Data list separator character
  134.  
  135. Example: ci$ = countryinfo$
  136.          print mid$(ci$,23,1) 'Print data list separator (USA=comma)
  137.  
  138. ================================================================================
  139. function createfile(f$)
  140.  
  141. Creates/opens a new file using the designated path\filename,
  142. and returns a handle to the file allowing subsequent access
  143. with the other DOS file commands.  If the specified file
  144. already exists, this routine will fail without affecting the
  145. specified file.  To truncate the specified file to zero length
  146. if it already exists, use MAKEFILE instead.  To open an
  147. existing file, use OPENFILE instead.
  148.  
  149. f$: Set to path\filename of new file to create
  150. createfile: Returns handle to the file, or 0 if error condition
  151.  
  152. Example: handle% = createfile(f$)
  153.          if handle% = 0 then print "Error creating"
  154.  
  155. ================================================================================
  156. function curdrive
  157.  
  158. Returns the drive code of the current (default) drive
  159. (0=A, 1=B, 2=C, etc...).  See SETDRIVE.
  160.  
  161. Example: print curdrive
  162.  
  163. ================================================================================
  164. function curdrivesize
  165.  
  166. Returns the size (in bytes) of the default (current)
  167. disk drive (this is not free space, but TOTAL space
  168. available).
  169.  
  170. curdrivesize: Returns capacity of drive in bytes
  171.  
  172. Example: print curdrivesize
  173.  
  174. ================================================================================
  175. function curdrivespace
  176.  
  177. Returns bytes free on current (default) drive.
  178. This is actual free space remaining.  To check
  179. total space, see CURDRIVESIZE.
  180.  
  181. Example: print curdrivespace
  182.  
  183. ================================================================================
  184. function datecode(yr%,mo%,dy%)
  185.  
  186. Translates a given date provided (year, month and day)
  187. into the word-length code DOS uses to store file date
  188. on a disk drive.  Can also be used to translate a date
  189. to a packed format for storage elsewhere.
  190.  
  191. yr%: Set to year (1980-2099)
  192. mo%: Set to month (1-12)
  193. dy%: Set to day (1-31)
  194. datecode: Returns word-length date encoded.
  195.  
  196. Example: dc??=datecode(1993,9,12)
  197.  
  198. ================================================================================
  199. sub decodedate(code??,yr%,mo%,dy%)
  200.  
  201. Decodes a DOS-encoded date (used for file date storage)
  202. back into a year-month-day format (see DATECODE).
  203. This can be used to decode any date encoded with DATECODE.
  204.  
  205. code??: Set to date code (see DATECODE)
  206. yr%: Returns year (1980-2099)
  207. mo%: Returns month (1-12)
  208. dy%: Returns day (1-31)
  209.  
  210. Example: decodedate c??,yr%,mo%,dy%
  211.  
  212. ================================================================================
  213. sub decodetime(code??,hr%,mn%,sc%)
  214.  
  215. Decodes a DOS-encoded time (used for file time storage)
  216. back into an hour/minutes/seconds format (see TIMECODE).
  217. This can be used to decode any time encoded with TIMECODE.
  218.  
  219. code??: Set to time code (see TIMECODE)
  220. hr%: Returns hour (0-23)
  221. mn%: Returns minute (0-59)
  222. sc%: Returns second (0-59)
  223.  
  224. Example: decodetime c??,h%,m%,s%
  225.  
  226. ================================================================================
  227. sub disabledrive(d%)
  228.  
  229. Disables the specified drive completely, disallowing access
  230. until drive is reenabled with enabledrive.  DOS 5+ ONLY.
  231.  
  232. d%: Set to drive to disable (0=A, 1=B...)
  233.  
  234. Example: disabledrive 0
  235.  
  236. ================================================================================
  237. function dosdataseg
  238.  
  239. Returns the data segment of MSDOS.SYS/IBMDOS.COM.
  240.  
  241. dosdataseg: Returns DOS data segment
  242.  
  243. Example: print dosdataseg
  244.  
  245. ================================================================================
  246. function doserr$(en%)
  247.  
  248. Returns text describing the extended DOS error code passed
  249. to this routine.  Use the number returned from other DOS routines
  250. in er%.  Unidentified errors will return "DOS Function Error."
  251.  
  252. en%: Set to DOS error number
  253. doserr$: Returns text describing DOS error code
  254.  
  255. Example: sethandlecount nhd%,er% 'See SETHANDLECOUNT
  256.          print doserr$(er%) 'Prints DOS error returned (0="OK")
  257.  
  258. ================================================================================
  259. sub dosflush
  260.  
  261. Flushes all open files, writing data to disk, without closing
  262. those files.  Same as PB FLUSH command, except that a file
  263. number cannot be specified - all data will always be flushed.
  264.  
  265. No parameters.
  266.  
  267. Example: dosflush
  268.  
  269. ================================================================================
  270. function dosinput$(mx%)
  271.  
  272. Uses a DOS function to input a string from the keyboard.  The
  273. characters are echoed to the display, and input may be redirected.
  274. Cursor might be hidden during input; use LOCATE ,,1 before calling
  275. if you want the cursor visible when the user is inputting data.
  276.  
  277. mx%: Set to maximum allowable length of input (1-255)
  278. dosinput$: Returns inputted string (exact length user entered).
  279.            User input is terminated with a carriage return.
  280.  
  281. Example: i$ = dosinput$(8)  'Get 8 chars. max
  282.  
  283. ================================================================================
  284. function dosinstat
  285.  
  286. Same as INSTAT, but uses a DOS function to detect if there
  287. are any keys in the keyboard buffer.
  288.  
  289. dosinstat: Returns 0 if no characters, -1 if at least one
  290.            character is available in the keyboard buffer.
  291.  
  292. Example:  while not dosinstat:wend  'wait for a keypress
  293.         kbdclr  'Clears keyboard buffer - see KBDCLR
  294.  
  295. ================================================================================
  296. sub dosprint(a$)
  297.  
  298. Prints a string using a DOS interrupt.
  299.  
  300. a$: Set to string to print, which should be terminated with
  301.     a "$" character to mark the end of the string for DOS.  If
  302.     you forget the $, DOS may print more than you had anticipated.
  303.     Obviously the string cannot contain a "$" character anywhere
  304.     except at the end.  No carriage return is printed at the end
  305.     of the string, and the PowerBASIC cursor is NOT updated (the
  306.     DOS cursor is, however, so the next call will print right after
  307.     the end of where the last call left off).
  308.  
  309. Example: dosprint "Hello!$"
  310.  
  311. ================================================================================
  312. function drivesize(d%)
  313.  
  314. Returns the size (in bytes) of the specified drive (this
  315. is not free space, but TOTAL space available).  If error
  316. (disk not in drive, etc) returns 0.
  317.  
  318. d%: Set to number of drive to check (0=default, 1=A, 2=B...)
  319. drivesize: Returns capacity of drive in bytes
  320.  
  321. Example: print drivesize(0)
  322.  
  323. ================================================================================
  324. function drivespace(d%)
  325.  
  326. Returns bytes free on specified drive.  This
  327. is the actual free space remaining.  To check
  328. total space available if disk were empty, see
  329. DRIVESIZE.  See BYTESFREE for another way to check
  330. bytes free on specified drive (commands are identical).
  331.  
  332. d%: Set to drive to check (0=current, 1=A, 2=B, 3=C...)
  333. drivespace: Returns bytes free on specified drive.
  334.  
  335. Example: print drivespace(1)
  336.  
  337. ================================================================================
  338. function driveused(d%)
  339.  
  340. Calculates number of bytes USED out of the total available
  341. for the specified drive.  For example, on a 10 meg disk, if
  342. there were exactly 3 megs free, this function would return
  343. 7168000 (7 megabytes used).
  344.  
  345. d%: Set to drive number to check (0=default, 1=A, 2=B...)
  346. driveused: Returns number of bytes used on specified drive
  347.  
  348. Example: print driveused(0)
  349.  
  350. ================================================================================
  351. sub enabledrive(d%)
  352.  
  353. Enables the specified drive, after disabling with DISABLEDRIVE.
  354. MS-DOS 5+ ONLY.
  355.  
  356. d%: Set to drive to enable.
  357.  
  358. Example: enabledrive 0
  359.  
  360. ================================================================================
  361. function fileattrib(f$)
  362.  
  363. Returns the attributes of a file.  Identical to PB's ATTRIB
  364. function, but does not require the use of ON ERROR to trap
  365. errors.  Not related to PB's FILEATTR command.
  366.  
  367. f$: Set to path\filename to get attributes for
  368. fileattrib: Returns file attributes (-1 if error):
  369. Bit 5 = Archive
  370. Bit 4 = Subdirectory
  371. Bit 2 = System
  372. Bit 1 = Hidden
  373. Bit 0 = Read only
  374.  
  375. Example: print fileattrib(f$)
  376.  
  377. ================================================================================
  378. sub findfirst(f$,atr%,er%)
  379.  
  380. Given a file spec, searches the default or specified directory
  381. for the first matching file, and returns file information in the
  382. current DTA.  Use GETDTA to get the address of the current Disk
  383. Transfer Area.  You can use the default DTA, but it's recommended
  384. that you set up your own DTA and use it, then use SETDTA afterwards
  385. to restore the address of the original DTA (see example below).
  386.  
  387. f$: Set to filespec of file to search for
  388. atr%: Set to attribute(s) to use in search (see FILEATTRIB for
  389.       attribute list)
  390. er%: Returns 0 if found, or error code if not found.
  391.  
  392. DTA layout:
  393. Bytes 0-20 = Reserved
  394. Byte 21 = Attribute of matched file
  395. Bytes 22-23 = File Time:
  396.               Bits 0bh-0fh = hours (0-23)
  397.               Bits 05h-0ah = minutes (0-59)
  398.               Bits 00h-04h = 2-sec increments (0-29)
  399. Bytes 24-25 = File Date:
  400.               Bits 09h-0fh = year (relative to 1980)
  401.               Bits 05h-08h = month (1-12)
  402.               Bits 00h-04h = day (1-31)
  403. Bytes 26-29 = File Size
  404. Bytes 30-42 = ASCIIZ filename and extension
  405.  
  406. Example: type    dtatype  'Set up for DTA type
  407.             filler as string * 21
  408.             attribute as byte
  409.             filetime  as word
  410.             filedate  as word
  411.             filesize  as dword
  412.             filename  as string * 13 'String terminated with 0 byte
  413.          end type
  414.          dim dta as dtatype 'Set up for new DTA
  415.          getdta s1??,o1?? 'Get current DTA address and keep it for later
  416.          setdta varseg(dta),varptr(dta) 'Set new DTA
  417.          f$="c:\*.exe":atr%=0 'Find "regular" *.exe files in C:\
  418.          findfirst f$,atr%,er% 'if er%=0, dta variable now contains file data
  419.          if er%=0 then print dta.filename 'Example of working with data
  420.          'work with more data here, use FINDNEXT, etc...
  421.          setdta s1??,o1?? 'Return to old DTA setting when done
  422.  
  423. ================================================================================
  424. sub findnext(er%)
  425.  
  426. Assuming a previous successful call to FINDFIRST (er%=0),
  427. finds the next matching file in the previously specified
  428. directory.  See FINDFIRST for example of setting up a new DTA
  429. and finding files.  Using this function assumes that the previous
  430. call to FINDFIRST contained one or more wildcard characters
  431. in the filespec (f$).
  432.  
  433. er%: Returns 0 if file found, and current DTA area filled
  434.      with file data, or errorcode if file not found.
  435.  
  436. Example: findnext er%  'er% will = 0 if another matching file found.
  437.  
  438. ================================================================================
  439. sub getcmosdate(cn%,yr%,mo%,dy%,rs%)
  440.  
  441. Obtains the current date from the CMOS clock chip.
  442. Similar to GETDATE, but gets the date from the CMOS
  443. chip directly, rather than the system date.
  444.  
  445. cn%: Returns century (19-20)
  446. yr%: Returns year
  447. mo%: Returns month
  448. dy%: Returns day
  449. rs%: Returns 1 if CMOS clock is running, or 0 if stopped
  450.      (Battery is drained, or no CMOS clock).
  451.  
  452. Example: getcmosdate cn%,yr%,mo%,dy%,rs%
  453.  
  454. ================================================================================
  455. sub getcmostime(hr%,mn%,sc%,dst%,rs%)
  456.  
  457. Obtains the time of day from the CMOS chip clock.
  458. Similar to GETTIME, but gets the time from the CMOS
  459. chip directly, rather than the system time.
  460.  
  461. hr%: Returns hours (0-23)
  462. mn%: Returns minutes (0-59)
  463. sc%: Returns seconds (0-59)
  464. dst%: Returns 0 if standard time, 1 if daylight savings time
  465. rs%: Returns 1 if clock is running, or 0 if stopped (battery
  466.      drained or other CMOS problem, or no CMOS clock).
  467.  
  468. Example: getcmostime hr%,mn%,sc%,dst%,rs%
  469.  
  470. ================================================================================
  471. sub getdate(yr%,mo%,dy%,dwk%)
  472.  
  473. Obtains the system day of the month, day of the week,
  474. month and year, using an MS-DOS call.
  475.  
  476. yr%: Returns year (1980-2099)
  477. mo%: Returns month (1-12)
  478. dy%: Returns day (1-31)
  479. dwk%: Returns day of the week (0=Sunday, 1=Monday...)
  480.  
  481. ================================================================================
  482. sub getdatime(h%,yr%,mo%,dy%,hr%,mn%,sc%)
  483.  
  484. Gets the date and time directory settings for
  485. a file.  File must be opened first using OPENFILE
  486. or one of the PB open commands.  Erroneous values will
  487. be returned if an unopened or incorrect handle is used.
  488.  
  489. h%:  Set to handle of previously opened file
  490. yr%: Returns year of file (1980-2099)
  491. mo%: Returns month of file (1-12)
  492. dy%: Returns day of file (1-31)
  493. hr%: Returns hour of file (0-23)
  494. mn%: Returns minutes of file (0-59)
  495. sc%: Returns seconds of file (0-59) (Not displayed in some DOS versions)
  496.  
  497. Example: open "i",#1,"filename" 'Open file
  498.          h% = fileattr(1,2) 'Get DOS file handle
  499.          getdatime h%,yr%,mo%,dy%,hr%,mn%,sc% 'Get file date/time data
  500.  
  501. ================================================================================
  502. sub getdta(sg??,ofs??)
  503.  
  504. Gets the current address of the disk transfer area (DTA), which
  505. is used for osme DOS disk-related functions, including the
  506. directory search functions.  See SETDTA.
  507.  
  508. sg??:  Returns segment of current Disk Transfer Area
  509. ofs??: Returns offset of current Disk Transfer Area
  510.  
  511. Example: call getdta(sg??,ofs??)
  512.  
  513. ================================================================================
  514. sub getindos(sg??,ofs??)
  515.  
  516. Gets the segment and offset address of the INDOS flag, which
  517. is incremented when a DOS function is called and decremented
  518. at the end of the call.
  519.  
  520. sg??:  Returns segment of DOS INDOS flag
  521. ofs??: Returns offset of DOS INDOS flag
  522.  
  523. Example: getindos sg??,ofs??
  524.  
  525. ================================================================================
  526. sub getswitchchar(ch%)
  527.  
  528. Gets the DOS switch character setting, which is used for
  529. command line switches.  Use SETSWITCHCHAR to change the
  530. current switch character.
  531.  
  532. ch%: Returns ASCII value of the current DOS switch character.
  533.  
  534. Example: getswitchchar ch%
  535.          print chr$(ch%) 'Displays DOS switch character
  536.  
  537. ================================================================================
  538. sub gettime(hr%,mn%,sc%)
  539.  
  540. Obtains the time of day from the system (DOS) clock.
  541.  
  542. hr%: Returns hours (0-23)
  543. mn%: Returns minutes (0-59)
  544. sc%: Returns seconds (0-59)
  545.  
  546. Example: call gettime(hr%,mn%,sc%)
  547.  
  548. ================================================================================
  549. sub getvector(i%,sg??,ofs??)
  550.  
  551. Obtains the address of the current interrupt handler
  552. routine for the specified machine interrupt.  See SETVECTOR.
  553.  
  554. i%: Set to interrupt number (0-255) to get
  555. sg??: Returns segment of handler for interrupt specified in i%
  556. ofs??: Returns offset of handler for interrupt specified in i%
  557.  
  558. Example: getvector 32,sg??,ofs??
  559.  
  560. ================================================================================
  561. sub getver(mj%,mn%)
  562.  
  563. Returns the version of MS-DOS currently in use.
  564.  
  565. mj%: Returns major version number (6 for DOS 6.20)
  566. mn%: Returns minor version number (20 for DOS 6.20)
  567.  
  568. Example: getver mj%,mn%
  569.  
  570. ================================================================================
  571. function isspooler
  572.  
  573. Checks if the DOS PRINT.COM print spooler is installed,
  574. and returns 0 if no, or -1 if yes.  Use this command before
  575. calling any of the other PBASMLIB SPOOL commands.
  576.  
  577. isspooler: Returns 0 if PRINT.COM not installed, -1 if installed,
  578.            257 if error condition (not OK to install).
  579.  
  580. Example: if isspooler = -1 then print "Print Spooler Ready"
  581.  
  582. ================================================================================
  583. sub kbdclr
  584.  
  585. Clears the keyboard buffer, removing all pending keystrokes.
  586.  
  587. No parameters.
  588.  
  589. Example: kbdclr
  590.  
  591. ================================================================================
  592. sub killfile(f$,er%)
  593.  
  594. Erases a file.  Similar to PB's KILL command, but can only
  595. erase one file at a time (does not accept wildcards), and
  596. returns an error code instead of forcing you to trap errors.
  597.  
  598. f$:  Set to path\filename to delete (no wildcards)
  599. er%: Returns 0 if file deleted, or error code if unsuccessful.
  600.  
  601. Example: killfile f$,er% 'er% = 0 if file killed successfully
  602.  
  603. ================================================================================
  604. function lastdoserr
  605.  
  606. Returns the extended error code for the last MS-DOS error
  607. encountered.  This could be from a DOS interrupt called from
  608. SHELL, by PowerBASIC, or that you called yourself.  Error number
  609. will stay the same until a new INT 21h DOS error occurs.
  610.  
  611. lastdoserr: Returns extended error code of last DOS error
  612.             encountered.  See DOSERR$
  613.  
  614. Example: print doserr$(lastdoserr) 'Returns text of last error
  615.  
  616. ================================================================================
  617. sub makedir(p$,er%)
  618.  
  619. Creates a directory using the specified path and drive.
  620. Same as PB's MKDIR command, but returns an error code rather
  621. than causing a PB error condition.
  622.  
  623. p$:  Set to drive\path to create
  624. er%: Returns error code or 0 if ok
  625.  
  626. Example: makedir p$,er% 'er%=0 if directory created successfully
  627.  
  628. ================================================================================
  629. function makefile(f$)
  630.  
  631. Creates/opens a new file using the designated path\filename,
  632. and returns a handle to the file allowing subsequent access
  633. with the other DOS file commands.  If the specified file
  634. already exists it is truncated to zero length, so be careful.
  635. You can create a file more safely using CREATEFILE instead,
  636. which fails if the specified filename exists rather than
  637. truncating it to zero length.
  638. To open an existing file, use OPENFILE instead.
  639.  
  640. f$: Set to path\filename of new file to create
  641. makefile: Returns handle to the file, or 0 if error condition
  642.  
  643. Example: handle% = makefile(f$)
  644.          if handle% = 0 then print "Error creating"
  645.  
  646. ================================================================================
  647. function malloc(np??,iseg??)
  648.  
  649. Allocates a block of memory from DOS and returns a
  650. pointer to the beginning of the allocated area.  Make
  651. sure to use SETMEM in PB to deallocate some of PB's memory
  652. first before attempting to allocate memory using this function.
  653. See MRELEASE and MRESIZE.
  654.  
  655. np??: Set to number of paragraphs (16-byte blocks) of memory
  656.       to allocate.
  657. iseg??: Returns initial segment of allocated block(s) if
  658.         successful, or size of largest available block if not
  659. malloc: Returns -1 if function successful, 0 if not.
  660.  
  661. Example: if malloc(10,iseg??) then print "Alloc Successful"
  662.          'Allocates 160 bytes, initial seg returned in iseg??
  663.  
  664. ================================================================================
  665. function mallocstrat
  666.  
  667. Obtains the code indicating the current MS-DOS strategy
  668. for allocating memory blocks (see MALLOC and related routines).
  669. See also SETMALLOC to change memory allocation strategy.
  670.  
  671. mallocstrat: Returns the following:
  672. 0 = First Fit - MS-DOS searches available memory blocks from
  673.     low to high addresses, assigning the first block large
  674.     enough to satisfy the MALLOC request. (Optimized SPEED).
  675.     This is the default MALLOC strategy.
  676. 1 = Best Fit - MS-DOS searches all available memory blocks
  677.     and assigns the smallest available block that will satisfy
  678.     the request, regardless of position (Optimized SIZE)
  679. 2 = Last Fit - MS-DOS searches the available memory blocks from
  680.     high to low addresses, assigning the highest one large enough
  681.     to satisfy the MALLOC request.
  682.  
  683. Example: ms% = mallocstrat
  684.  
  685. ================================================================================
  686. function mrelease(sg??)
  687.  
  688. Releases a block of memory previously allocated with MALLOC.
  689.  
  690. sg??: Set to segment of block to release (iseg?? in MALLOC)
  691. mrelease: Returns -1 if function successful or 0 if not.
  692.  
  693. Example: if mrelease(sg??) then print "Memory Released."
  694.  
  695. ================================================================================
  696. function mresize(nbs??,sg??,mbs??)
  697.  
  698. Dynamically shrinks or extends a memory block.  Use in
  699. conjunction with MALLOC and MRELEASE to dynamically allocate,
  700. deallocate and resize blocks of memory.
  701.  
  702. nbs??: Set to new block size in paragraphs
  703. sg??:  Set to segment of block to be modified (iseg?? in MALLOC)
  704. mbs??: If error, Returns maximum block size available (paragraphs)
  705. mresize: Returns -1 if ok or 0 if error
  706.  
  707. Example: if mresize(nbs??,sg??,mbs??) then print "Resize Successful."
  708.  
  709. ================================================================================
  710. function openfile(f$)
  711.  
  712. Opens an existing file and returns a handle to the file allowing
  713. subsequent access by the other DOS file commands.  If file does
  714. not already exist, use MAKEFILE instead.  PBASMLIB always opens
  715. the file for read/write access, so you can do either or both.
  716.  
  717. f$: Set to path\filename of file to open
  718. openfile: Returns handle to the file, or 0 if an error
  719.           occurred (such as file does not exist).
  720.  
  721. Example: handle% = openfile(f$) 'handle% is the handle to the file
  722.          if handle%=0 then stop 'Error opening
  723.  
  724. ================================================================================
  725. sub prnout(a$)
  726.  
  727. Sends a character to the first list device (PRN or LPT1),
  728. unless redirected with the DOS MODE command.  If printer is
  729. busy or offline, keyboard may lock (usually temporarily).
  730.  
  731. a$: Set to single character to send to printer.  If string
  732.     is longer than one character, only the first character
  733.     will be sent to the printer.
  734.  
  735. Example: prnout "X"
  736.  
  737. ================================================================================
  738. function pspseg
  739.  
  740. Returns the segment address of the Program Segment Prefix
  741. (PSP) for the currently executing program.  Executing this
  742. function in the PB IDE will return the PSP address for PB.EXE.
  743. The PSP can be accessed to find out information about the
  744. program that's currently executing, including path\filename.
  745.  
  746. pspseg: Returns segment of PSP.
  747.  
  748. Example: def seg = pspseg
  749.  
  750. ================================================================================
  751. sub readfile(h%,numbytes??,sg??,ofs??,nbr??)
  752.  
  753. Reads data from a file, given a valid file handle from MAKEFILE
  754. or OPENFILE, or from using PB's FILEATTR(FILENUM,2) command.
  755.  
  756. h%: Set to handle retrieved with MAKEFILE, OPENFILE, or FILEATTR
  757.     if the file was opened by PB.
  758. numbytes??: Set to number of bytes to read from the file (1-65535)
  759. sg??: Set to segment of buffer area to hold file data
  760. ofs??: Set to offset of buffer area to hold file data
  761. nbr??: Returns number of bytes read (0 if none or error)
  762.  
  763. Example: s$=space$(64) 'Reserve 64 bytes in a string
  764.          readfile h%,64,strseg(s$),strptr(s$),nb?? 'Read 64 bytes into s$
  765.          print nb??;" bytes read from file."
  766.  
  767. ================================================================================
  768. sub readsectors(d%,ns%,ss%,sg??,ofs??,e1%,e2%)
  769.  
  770. Allows reading of specific logical disk sectors into
  771. memory.  Logical sector numbers are obtained by numbering
  772. each disk sector sequentially from track 0, head 0, sector
  773. 1, and continuing until the last sector on the disk is counted.
  774. See WRITESECTORS.
  775.  
  776. d%: Set to drive to read from (0=A, 1=B, 2=C...)
  777. ns%: Set to number of sectors to read
  778. ss%: Set to starting sector number
  779. sg??: Set to segment value of buffer to hold sector data
  780. ofs??: Set to offset value of buffer to hold sector data
  781. e1%: Returns the following error codes:
  782.      0 = OK (Use this to check for errors)
  783.      1 = bad command                2 = bad address mark
  784.      4 = requested sector not found    8 = DMA failure
  785.     16 = Data CRC error                32 = controller failed
  786.     64 = seek operation failed         128 = attachment failed to respond
  787. e2%: Returns the following error codes:
  788.      0 = write protect error        1 = unknown unit
  789.      2 = drive not ready             3 = unknown command
  790.      4 = data CRC error            5 = bad request structure length
  791.      6 = seek error                 7 = unknown media type
  792.      8 = sector not found        9 = printer out of paper
  793.     10 = write fault             11 = read fault
  794.     12 = general failure           15 = invalid disk change
  795.  
  796. Example: readsectors 0,5,1,sg??,ofs??,e1%,e2%
  797.          if e1%=0 the print "Read OK."
  798.  
  799. ================================================================================
  800. sub redirect(h1%,h2%)
  801.  
  802. Allows you to refer a handle to the same device or file
  803. as another handle, thus redirecting that handle.
  804.  
  805. h1%: Set to handle to be redirected to (file or device)
  806. h2%: Set to handle to redirect
  807.  
  808. Example: redirect h1%,h2%  'Redirects handle h2% to handle h1%
  809.  
  810. ================================================================================
  811. sub removedir(p$,er%)
  812.  
  813. Removes a directory using the specified path and drive.  Same
  814. as PB's RMDIR command, but returns an error code instead of
  815. making you trap errors with the ON ERROR command.
  816.  
  817. p$: Set to drive\path to delete
  818. er%: Returns error code, or 0 if ok.
  819.  
  820. Example: removedir p$,er% 'er%=0 if directory removed
  821.  
  822. ================================================================================
  823. sub setattrib(f$,attr%,er%)
  824.  
  825. Sets the attributes of a file.  Similar to PB's ATTRIB command,
  826. but does not require the use of ON ERROR to trap errors.
  827. (See FILEATTRIB) for attribute list
  828.  
  829. f$: Set to filename to change attribute
  830. attr%: Set to new attribute for file
  831. er%: Returns 0 if ok (attribute set) or error code if error
  832.  
  833. Example: setattrib f$,attr%,er% 'er%=0 if attribute set successfully
  834.  
  835. ================================================================================
  836. sub setbreak(b%)
  837.  
  838. Sets or clears the system break flag, which influences CTRL-C
  839. checking when a DOS function is in progress.  When BREAK=ON,
  840. they keyboard is examined for a CTRL-C whenever any I/O is
  841. requested ; when off, it's examined only when executing the
  842. character I/O functions.
  843.  
  844. b%: Set to 0 to set BREAK=OFF, or 1 to set BREAK=ON
  845.  
  846. Example: setbreak 1
  847.  
  848. ================================================================================
  849. sub setcmosdate(cn%,yr%,mo%,dy%)
  850.  
  851. Sets the CMOS time date's chip clock to a
  852. specific date.  Differs from SETDATE in that
  853. only the CMOS chip date setting is affected, not
  854. the system date.  In many versions of DOS, using
  855. SETDATE will affect both the DOS date and the CMOS
  856. date.
  857.  
  858. cn%: Set to century (19 or 20)
  859. yr%: Set to year (00-99)
  860. mo%: Set to month (1-12)
  861. dy%: Set to day (1-31)
  862.  
  863. Example: setcmosdate cn%,yr%,mo%,dy%
  864.  
  865. ================================================================================
  866. sub setcmostime(hr%,mn%,sc%,dst%)
  867.  
  868. Sets the CMOS time/date's chip clock.
  869. This function differs from SETTIME only
  870. in that it sets the CMOS chip time only, and
  871. does not affect the DOS clock.  In many versions
  872. of DOS, setting the DOS clock will also set the
  873. CMOS clock.
  874.  
  875. hr%: Set to hour (0-23)
  876. mn%: Set to minute (0-59)
  877. sc%: Set to second (0-59)
  878. dst%: Set to 0 if standard time, 1 if daylight savings time
  879.  
  880. Example: setcmostime 0,0,0,0 'Set clock to midnight standard time
  881.  
  882. ================================================================================
  883. sub setdate(yr%,mo%,dy%)
  884.  
  885. Sets the system date using a DOS call.  If date is invalid,
  886. old setting will not be changed. (see GETDATE)
  887.  
  888. yr%: Set to year (1980-2099)
  889. mo%: Set to month (1-12)
  890. dy%: Set to day (1-31)
  891.  
  892. Example: setdate 1993,11,28 'The day this routine was written
  893.  
  894. ================================================================================
  895. sub setdatime(h%,yr%,mo%,dy%,hr%,mn%,sc%)
  896.  
  897. Sets the date and time directory settings for a
  898. file.  File must be opened first using OPENFILE or
  899. one of the PB open commands.  See GETDATIME.
  900.  
  901. h%:  Set to handle of previously opened file
  902. yr%: Set to year of file (1980-2099)
  903. mo%: Set to month of file (1-12)
  904. dy%: Set to day of file (1-31)
  905. hr%: Set to hour of file (0-23)
  906. mn%: Set to minutes of file (0-59)
  907. sc%: Set to seconds of file (0-59)
  908.  
  909. Example: open "i",#1,"filename" 'Open file
  910.          h% = fileattr(1,2) 'Get DOS file handle
  911.          getdatime h%,yr%,mo%,dy%,hr%,mn%,sc% 'Get file date/time data
  912.          dy%=dy%+1 'Add one to the date (day)
  913.          setdatime h%,yr%,mo%,dy%,hr%,mn%,sc% 'Set file date/time data
  914.  
  915. ================================================================================
  916. function setdrive (d%)
  917.  
  918. Selects the specified drive to be the current drive
  919. and returns the total number of logical drives in the
  920. system.
  921.  
  922. d%: Set to disk to select (0=A, 1=B, 2=C etc).
  923. setdrive: Returns total logical drives in system.  Always
  924.          equals 5, or the value of the LASTDRIVE statement
  925.          in CONFIG.SYS, whichever is greater.
  926.  
  927. Example: a%=setdrive(0) 'a% = total number of logical drives
  928. Example: setdrive 0  'Set drive and discard return value
  929.  
  930. ================================================================================
  931. sub setdta(sg??,ofs??)
  932.  
  933. Specifies the address of the disk transfer area (DTA), which
  934. is used for some DOS disk-related functions, including the
  935. directory search functions.  If this routine is never called,
  936. the DTA defaults to a 128-byte buffer at offset 80h in the
  937. Program Segment Prefix
  938.  
  939. sg??:  Set to segment of new disk transfer area address
  940. ofs??: Set to offset of new disk transfer area address
  941.  
  942. Example: setdta strseg(s$),strptr(s$) 'Set s$ to DTA area
  943.  
  944. ================================================================================
  945. sub setfilepointer(handle%,p&)
  946.  
  947. Sets the file location pointer relative to the start
  948. of the file.  Similar to PB's SEEK command.
  949.  
  950. handle%: Set to handle returned by a previous call to
  951. OPENFILE or MAKEFILE.
  952. p&: Set to file pointer value (absolute offset from start of file).
  953.     Start of file is always 0 with this command.
  954.  
  955. Example: setfilepointer h%,5 'Go to byte #5
  956.  
  957. ================================================================================
  958. sub sethandlecount(nhd%,er%)
  959.  
  960. Sets the maximum number of files and devices that may be
  961. opened at once using handles by the current process.
  962. Attempts to increase/decrease size of handle table (default
  963. is 20).  It's recommended you use a statement like "d=setmem
  964. (-1000)" first to free some memory for DOS to store more file
  965. handles if you intend to increase the handle count.
  966.  
  967. nhd%: Set to number of handles desired
  968. er%:  Returns 0 if function successful, or error code if not
  969.  
  970. Example: sethandlecount 25,er%
  971.          if er%=0 then print "25 handles set."
  972.  
  973. ================================================================================
  974. sub setmalloc(m%)
  975.  
  976. Sets the code indicating the current MS-DOS strategy for
  977. allocating free memory blocks (see MALLOCSTRAT and MALLOC).
  978. Use MALLOCSTRAT afterward to verify that new allocation strategy
  979. was indeed set by MS-DOS.
  980.  
  981. m%: Set to allocation strategy desired (see MALLOCSTRAT for
  982.     explanation of values.
  983.  
  984. Example: setmalloc 1
  985.  
  986. ================================================================================
  987. sub setswitchchar(ch%)
  988.  
  989. Allows setting of the DOS switch character, used for
  990. command line switches.  Use GETSWITCHCHAR to retrieve
  991. the current DOS switch character.
  992.  
  993. ch%: Set to ASCII value of new DOS switch character.
  994.  
  995. Example: setswitchchar asc("#") 'Change it to "#"
  996.  
  997. ================================================================================
  998. sub settime(hr%,mn%,sc%)
  999.  
  1000. Sets the system realtime clock (DOS clock).
  1001. (See GETTIME)
  1002.  
  1003. hr%: Set to hours (0-23)
  1004. mn%: Set to minutes (0-59)
  1005. sc%: Set to seconds (0-59)
  1006.  
  1007. Example: settime hr%,mn%,sc%
  1008.  
  1009. ================================================================================
  1010. sub setvector(i%,sg??,ofs??)
  1011.  
  1012. Sets a machine interrupt vector to point to an interrupt
  1013. handling routine.
  1014.  
  1015. i%: Set to interrupt number to change (0-255)
  1016. sg??: Set to segment of interrupt handler
  1017. ofs??: Set to offset of interrupt handler
  1018.  
  1019. Example: setvector i%,sg??,o??
  1020.  
  1021. ================================================================================
  1022. sub setverify(vf%)
  1023.  
  1024. Sets the dos read-after-write (verify) flag on or off.
  1025. The default setting is off.  See VERIFYFLAG function.
  1026. VERIFY mode results in slower, but more reliable, disk
  1027. transfers.
  1028.  
  1029. vf%: Set to 1 to turn VERIFY on, or 0 to turn VERIFY off.
  1030.  
  1031. Example: setverify 1  'Set verify flag on
  1032.  
  1033. ================================================================================
  1034. sub spoolcancel(er%)
  1035.  
  1036. Cancels all files in the PRINT.COM print queue.
  1037. See SPOOLSUBMIT for more details.  Make sure PRINT.COM
  1038. is loaded first with ISSPOOLER before calling.
  1039.  
  1040. er%: Returns error code, or 0 if ok.
  1041.  
  1042. Example: call spoolcancel(er%)
  1043.  
  1044. ================================================================================
  1045. sub spoolhold(er%)
  1046.  
  1047. Puts all print jobs in the PRINT.COM queue on hold until
  1048. released with SPOOLRELEASE.  See SPOOLSUBMIT for more details.
  1049.  
  1050. er%: Returns 0 if ok, or error code if error
  1051.  
  1052. Example: call spoolhold(er%)
  1053.          if er%=0 then print "Printing on hold."
  1054.  
  1055. ================================================================================
  1056. sub spoolrelease(er%)
  1057.  
  1058. Releases the hold put on print jobs in the PRINT.COM
  1059. queue with SPOOLHOLD.  See SPOOLHOLD and SPOOLSUBMIT
  1060. for further details.
  1061.  
  1062. er%: Returns 0 if ok, or error code if error
  1063.  
  1064. Example: call spoolrelease(er%)
  1065.          if er%=0 then print "Print Hold Released"
  1066.  
  1067. ================================================================================
  1068. sub spoolremove(f$,er%)
  1069.  
  1070. Removes a file from the PRINT.COM print queue.  See
  1071. SPOOLSUBMIT for more information.
  1072.  
  1073. f$: Set to path\filename of file to remove from print queue
  1074. er%: Returns 0 if ok, or error code if error.
  1075.  
  1076. Example: spoolremove f$,er%
  1077.          if er%<>0 then print "Error removing ";f$
  1078.  
  1079. ================================================================================
  1080. sub spoolsubmit(f$,er%)
  1081.  
  1082. Submits a file for printing to the PRINT.COM DOS TSR
  1083. program.  Check if PRINT.COM is loaded first with ISSPOOLER
  1084. before using this command.  Note: The print spooler does not
  1085. seem to work within PB's IDE, and can only be used in a standalone
  1086. .EXE file.
  1087.  
  1088. f$: Set to full path\filename of file to submit for printing.
  1089.     (CAN include wildcard characters).
  1090. er%: Returns 0 if successful (file submitted), or error
  1091.      code if unsuccessful (file not submitted for printing).
  1092.  
  1093. Example: spoolsubmit fi$,er%
  1094.          print doserr$(er%) 'Prints "OK" if file submitted.
  1095.  
  1096. ================================================================================
  1097. function thispath$
  1098.  
  1099. Returns the path of the program currently executing, letting
  1100. you determine where it's data files are stored.  See THISPROGRAM$.
  1101.  
  1102. thispath$: Returns path of current program with trailing backslash
  1103.  
  1104. Example: print thispath$
  1105.  
  1106. ================================================================================
  1107. function thisprogram$
  1108.  
  1109. Returns the full path and filename of the
  1110. currently executing program (will return PB.EXE
  1111. when in the PowerBASIC IDE).
  1112.  
  1113. thisprogram$: Returns path\programname
  1114.  
  1115. Example: print thisprogram$
  1116.  
  1117. ================================================================================
  1118. function timecode(hr%,mn%,sc%)
  1119.  
  1120. Translates a given time (hour, minutes, seconds)
  1121. into a word-length coded format DOS uses to store
  1122. file times on a disk drive.  Can also be used to
  1123. translate a time to a packed format for storage elsewhere.
  1124. Odd-numbered seconds values will lose accuracy due to translation
  1125. to 2-second interval format by the encoding routine.
  1126.  
  1127. hr%: Set to hour (0-23)
  1128. mn%: Set to minutes (0-59)
  1129. sc%: Set to seconds (0-59)
  1130.  
  1131. Example: print timecode(15,32,11)
  1132.  
  1133. ================================================================================
  1134. function verifyflag
  1135.  
  1136. Returns the status of the DOS read-after-write (verify)
  1137. flag.  See SETVERIFY.
  1138.  
  1139. verifyflag: Returns 1 if verify on or 0 if off.
  1140.  
  1141. Example: print verifyflag
  1142.  
  1143. ================================================================================
  1144. sub writefile(h%,numbytes??,sg??,ofs??,nbw??)
  1145.  
  1146. Writes data to a file, given a valid file handle from MAKEFILE
  1147. or OPENFILE, or from using PB's FILEATTR(FILENUM,2) command.
  1148.  
  1149. h%: Set to handle retrieved with MAKEFILE, OPENFILE, or FILEATTR
  1150.     if the file was opened by PB.
  1151. numbytes??: Set to number of bytes to write to the file (1-65535)
  1152. sg??: Set to segment of buffer area holding data to write
  1153. ofs??: Set to offset of buffer area holding data to write
  1154. nbw??: Returns number of bytes written (0 if none or error)
  1155.  
  1156. Example: writefile h%,len(s$),strseg(s$),strptr(s$),nb?? 'write contents of s$ to file h%
  1157.          print nb??;" bytes written to file."
  1158.  
  1159. ================================================================================
  1160. sub writesectors(d%,ns%,ss%,sg??,ofs??,e1%,e2%)
  1161.  
  1162. Allows writing of specific logical disk sectors from memory.
  1163. Logical sector numbers are obtained by numbering
  1164. each disk sector sequentially from track 0, head 0, sector
  1165. 1, and continuing until the last sector on the disk is counted.
  1166. See READSECTORS.  Caution: This routine can damage disk data!
  1167.  
  1168. d%: Set to drive to write to (0=A, 1=B, 2=C...)
  1169. ns%: Set to number of sectors to write
  1170. ss%: Set to starting sector number
  1171. sg??: Set to segment value of buffer holding sector data
  1172. ofs??: Set to offset value of buffer holding sector data
  1173. e1%: Returns the following error codes:
  1174.      0 = OK (Use this to check for errors)
  1175.      1 = bad command                2 = bad address mark
  1176.      4 = requested sector not found     8 = DMA failure
  1177.     16 = Data CRC error                 32 = controller failed
  1178.     64 = seek operation failed          128 = attachment failed to respond
  1179. e2%: Returns the following error codes:
  1180.      0 = write protect error        1 = unknown unit
  1181.      2 = drive not ready             3 = unknown command
  1182.      4 = data CRC error            5 = bad request structure length
  1183.      6 = seek error                 7 = unknown media type
  1184.      8 = sector not found        9 = printer out of paper
  1185.     10 = write fault             11 = read fault
  1186.     12 = general failure           15 = invalid disk change
  1187.  
  1188. Example: writesectors 0,5,1,sg??,ofs??,e1%,e2%
  1189.          if e1%=0 the print "Write OK."
  1190.  
  1191.